<div class="modal-body">
	<form id="user-form" name="user-form" class="form-horizontal">
		<input type="hidden" name="zhtId" id="zhtId">
		<input type="hidden" name="createTime" data-flag="date" data-format="yyyy-MM-dd HH:mm:ss">
		<input type="hidden" name="deleted">
		<div class="box-body">
			<div class="col-md-6">
				<div class="form-group">
					<label for="project_id" class="col-sm-3 control-label">所属项目</label>
					<div class="col-sm-8">
						<select id="project_id" class="form-control" name="project_id">
								<option value="" label="请选择所属项目"/>
						</select>
					</div>
				</div>
				<div class="form-group">
					<label for="location_lng" class="col-sm-3 control-label">地域经度</label>
					<div class="col-sm-8">
						<input type="text" class="form-control" id="location_lng" name="location_lng" placeholder="地域经度">
					</div>
				</div>
				
			</div>
			<div class="col-md-6">
				<div class="form-group">
					<label for="name" class="col-sm-4 control-label">灾害点名称</label>
					<div class="col-sm-7">
						<input type="text" class="form-control" id="name" name="name" placeholder="灾害点名称">
					</div>
				</div>
				<div class="form-group">
					<label for="location_lat" class="col-sm-4 control-label">地域纬度</label>
					<div class="col-sm-7">
						<input type="text" class="form-control" id="location_lat" name="location_lat" placeholder="地域纬度">
					</div>
				</div>
			</div>			
		</div>
		<!-- /.box-body -->
		<div class="box-footer text-right">
			<!--以下两种方式提交验证,根据所需选择-->
			<button type="button" class="btn btn-default" data-btn-type="cancel" onclick="dialog_close()">取消</button>
			<button type="button" class="btn btn-primary" data-btn-type="save" onclick="save_zht()">提交</button>
		</div>
		<!-- /.box-footer -->
	</form>
</div>
<script type="text/javascript">
	$(document).ready(function(){
		initProject( "project_id", view_zht );
	});

	function initProject( sel_id, fn ){
		var url = "../../tbl_project/list";
		var paramMap = {};
		paramMap.page = 0;
		paramMap.city_code = global.system_city_code;
		paramMap.pagesize = 999;
		var json_data = JSON.stringify( paramMap );
		$.ajax({
			  url: url,
			  type : 'post',
			  async : false,
			  data: json_data,
			  contentType: "application/json; charset=utf-8",
			  dataType: "json",
			  success: function( json ) {
				  $(json.data).each(function(){
						$( "#" + sel_id ).append("<option value='"+ this.id +"'>"+ this.name +"</option>");
				  });
				  if( fn ){
					  fn();
				  }
			  }
		});
	}
	
	function view_zht( fn ){
		//从datatable上获取已经选择的条目
		if( Dtable_zht.rows('.selected').data().length > 0 ){
			var id = Dtable_zht.rows('.selected').data()[0].id;
			$("#zhtId").val( id );
			
			if( id == "null" ||id == null || id == undefined || id == "0" ){
				return false;
			}
			//说明是查询
			$("#id").val(id);
			$("[name='btn_sys_config_delete']").attr("disabled", false);
			var url = "../../tbl_zht/" + id;
			$.getJSON(url, null, function(json){
				//向页面上加载信息
				if( json && json.data ){
					var zht = json.data;
					$("#zhtId").val(zht.id);
					$("#name").val(zht.name );
			 		$("#project_id").val(zht.project_id);
			 		$("#location_lat").val(zht.location_lat);
			 		$("#location_lng").val(zht.location_lng);
				}			
			});
		}
	}
	
	function save_zht( fn ){
		var zht = {};
		zht.id = $("#zhtId").val();
		zht.name = $("#name").val();
		zht.project_id = $("#project_id").val();
		zht.location_lat = $("#location_lat").val();
		zht.location_lng = $("#location_lng").val();
		var json_data = JSON.stringify( zht );
		var url = "../../tbl_zht/save";
		$.ajax({
			  url: url,
			  type : 'post',
			  async : false,
			  data: json_data,
			  contentType: "application/json; charset=utf-8",
			  dataType: "json",
			  success: function(json) {
				 global.alert(json.message);
				 $("#zht_main").load("zht/zht_list.html");
				 dialog_close();
				 if(fn){fn();}
			  }
		});
	}
	
	function dialog_close(){
		global.dialog.close()
	}
</script>